<?php
/**
 * $Id: contacts_controller.php 1005 2011-11-09 06:26:32Z manu $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 1005 $
 * @lastModifiedBy		$LastChangedBy: manu $
 * @lastChanged			$Date: 2011-11-09 11:56:32 +0530 (Wed, 09 Nov 2011) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Handles AJAX live events page
 *
 */
class ContactsController extends CmsAppController
{
	var $name = 'Contacts';
	var $helpers = array('Html','Form', 'Javascript');
	var $components = array('RequestHandler','Email');

	function add() 
	{
		$this->pageTitle = __('Contact us');
		if ($this->RequestHandler->isPost()) 
		{
			$this->Contact->set($this->data);
			if($this->verifyCaptcha($this->data['Contact']['captcha']) == false)
			{
				$this->errorMsg(__('Please enter a valid captcha code.',true));
			}
			else
			{
				if ($this->Contact->validates()) 
				{
					//send email using the Email component
					$this->Email->to = Configure::read('cmsConfig.Backend.email');  
					$this->Email->subject = 'Contact message from ' . $this->data['Contact']['name'];
					$this->Email->setFrom($this->data['Contact']['email']); 
					$this->Email->sendAs = 'both';
					$this->Email->template = 'contact_form';
					if($this->Email->send())
					{
						$this->successMsg(__('Thank you for writing to us. We will reply to you soon.',true));
					}
					else
					{
						$this->errorMsg(__('Mail could not be sent. Please try again later.',true));
					}
					$this->redirect('/');
				}
			}
		}
	}
}//end of class
?>